﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using HexChessBoard.PlayerComponents;

namespace HexChessBoard
{
    public static class DrawSupport
    {
        public static void DrawModel(Model model, Matrix worldTransform, Matrix[] absoluteBoneTransforms, SimpleCamera camera, Vector3 specularColor)
        {
            //Matrix projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, ScreenManager.GraphicsDevice.Viewport.AspectRatio, .01f, 1000);
            //Matrix viewMatrix = Matrix.CreateLookAt(new Vector3(-board.Tiles[5, 5].Position.X - 20, 150, board.Tiles[5, 5].Position.Z), board.Tiles[5, 5].Position, Vector3.Up);

            // nothing tricky in here; this is the same model drawing code that we see
            // everywhere. we'll loop over all of the meshes in the model, set up their
            // effects, and then draw them.
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.PreferPerPixelLighting = true;
                    effect.SpecularColor = specularColor;
                    effect.DirectionalLight0.Direction = new Vector3(-1, -.5f, -1f);
                    //effect.DirectionalLight0.Direction = new Vector3(0, 0, -1f);
                    effect.View = camera.ViewMatrix;
                    effect.Projection = camera.ProjectionMatrix;
                    effect.World = absoluteBoneTransforms[mesh.ParentBone.Index] * worldTransform;
                }
                mesh.Draw();
            }
        }
    }
}
